package com.jack.vipmis.vip.api.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jack.vipmis.common.web.controller.BaseController;
import com.jack.vipmis.vip.api.util.MsgInfo;
import com.jack.vipmis.vip.wei.entity.WeiReplyEntity;
import com.jack.vipmis.vip.wei.service.WeiReplyEntityService;

/**
 * 微贴回复Action
 * 
 * @author JackLiang
 * @version 1.0
 * @date 2014-8-27
 */
@Controller
@RequestMapping(value = "api/weiReply")
public class WeiReplyApiController extends BaseController<WeiReplyEntity, Long> {

	@Autowired
	private WeiReplyEntityService	weiReplyEntityService;

	/**
	 * 回复微贴
	 * 
	 * @param weiId 微贴ID
	 * @param userId 用户ID
	 * @param content 回复的内容
	 * @return
	 */
	@RequestMapping(value = "add", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> add(@RequestParam("weiId") long weiId, @RequestParam("userId") long userId,
			@RequestParam("content") String content) {
		WeiReplyEntity m = new WeiReplyEntity();
		m.setWeiId(weiId);
		m.setReplyContent(content);
		m.setUserId(userId);

		WeiReplyEntity w = weiReplyEntityService.save(m);
		if (w != null) {
			return MsgInfo.ok(w);
		} else {
			return MsgInfo.fail();
		}
	}

	/**
	 * 获取评论列表
	 * 
	 * @param page
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "list")
	@ResponseBody
	public Map<String, Object> list(@RequestParam("page") int page, @RequestParam("id") long id) {
		try {
			Page<WeiReplyEntity> result = weiReplyEntityService.list(page, id);
			return MsgInfo.ok(result.getContent());
		} catch (Exception e) {
			// 未处理
			return MsgInfo.fail();
		}

	}
}
